//
//  cardtest4.c
//  Dominion
//
//  Eric Hook
//  hooke@onid.orst.edu
//  CS362 Winter 2014
//

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

int seed = 1000;
int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, salvager, village, baron, great_hall};

void testCardEffectVerifySalvagerAddBuyDecreaseCardInHand() {
    int result = 0;
    int card = salvager;
    int choice1 = 1;
    int choice2 = 2;
    int choice3 = 3;
    int bonus = 0;
    struct gameState G;
    int currentPlayer = 0;
    int preSalvagerNumBuys = 0;
    int preSalvagerCardInHand = 0;
    int postSalvagerNumBuys = 0;
    int postSalvagerCardInHand = 0;
    int playSavlvager = 0;
    
    printf ("TESTING: int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) : salvager : cardTest3.c.\n");
    
    memset(&G, 23, sizeof(struct gameState));       // clear the game state
    result = initializeGame(2, k, seed, &G);
    assert(result == 0);                            // validate that the game was inititalized correctly
    
    preSalvagerNumBuys = G.numBuys;
    printf("preSalvagerNumBuys = %d\n", preSalvagerNumBuys);
    preSalvagerCardInHand = G.handCount[currentPlayer];
    printf("preSalvagerCardInHand = %d\n", preSalvagerCardInHand);  // if 0 (false) passed in for choice1 only 1 card discarded, else 2
    
    playSavlvager = cardEffect(card, choice1, choice2, choice3, &G, 1, &bonus);
    
    postSalvagerNumBuys = G.numBuys;
    printf("postSalvagerNumBuys = %d\n", postSalvagerNumBuys);
    postSalvagerCardInHand = G.handCount[currentPlayer];
    printf("postSalvagerCardInHand = %d\n", postSalvagerCardInHand); // if 0 (false) passed in for choice1 only 1 card discarded, else 2
    
    assert ( (preSalvagerNumBuys + 1) == postSalvagerNumBuys);      // number of buys should increase
    if (choice1 == 0) {
        assert (postSalvagerCardInHand == (preSalvagerCardInHand - 1) ); // if choice1 is 0, two discards
    }
    if (choice1 != 0) {
        assert (postSalvagerCardInHand == preSalvagerCardInHand - 2);  // if choice1 is !0, only one discard
    }
    
    printf("!!! PASS: testCardEffectVerifySalvagerAddBuyDecreaseCardInHand()");

}

int main () {
    testCardEffectVerifySalvagerAddBuyDecreaseCardInHand();
    return 0;
}